<template>
	<view class="">
		<view class="" style="padding-bottom: 120rpx;">
			<view class="mainpadding ffffff">
				<view class="ershiba nofonweight xiaohei">缩略图</view>
				<view class="margin_top shangc" v-if="!logo" @click="uploadImg(1)">
					<image src="../static/image/system/shangchuan.png" mode=""></image>
				</view>
				<view class="margin_top shangc" v-if="logo" @click="uploadImg(1)">
					<image :src="logo_text" mode=""></image>
				</view>
				<view class="ershiba nofonweight xiaohei margin_top">详情图（{{images_text.length}}/5）</view>
				<view class="flexleft flex_wrap">
					<view class="shilitu margin_top margin_right2 dingwei" v-for="(item,index) in images_text"
						:key="index">
						<image :src="item" mode=""></image>
						<view class="shanchu" @click="delindex(index,images_text,images)">
							<u-icon name="close-circle-fill"></u-icon>
						</view>
					</view>
					<view class="margin_top shangc margin_right2" v-if="images.length<5"
						@click="uploadImg(5,images,images_text)">
						<image src="../static/image/system/shangchuan.png" mode=""></image>
					</view>
				</view>
			</view>
			<view class="mainpadding ffffff margin_top1">
				<view class="xiahuaxian flexbetween margin_top">
					<view class="ershiba nofonweight xiaohei">姓名</view>
					<input type="text" class="textright" placeholder="请输入" v-model="name" style="width: 80%;">
				</view>
				<view class="xiahuaxian flexbetween margin_top">
					<view class="ershiba nofonweight xiaohei">年龄</view>
					<input type="number" class="textright" placeholder="请输入" v-model="age" style="width: 80%;">
				</view>
				<view class="xiahuaxian flexbetween margin_top">
					<view class="ershiba nofonweight xiaohei">性别</view>
					<view class="flexright">
						<u-radio-group v-model="gender" placement="row" circle>
							<u-radio activeColor="#1ba95b" :customStyle="{marginRight: '30rpx'}" label="男"
								name="1"></u-radio>
							<u-radio activeColor="#1ba95b" label="女" name="2"></u-radio>
						</u-radio-group>
					</view>
				</view>
				<view class="xiahuaxian flexbetween margin_top">
					<view class="ershiba nofonweight xiaohei">联系电话</view>
					<input type="number" class="textright" placeholder="请输入" v-model="mobile" style="width: 80%;">
				</view>
				<view class="xiahuaxian flexbetween margin_top">
					<view class="ershiba nofonweight xiaohei">身份证号</view>
					<input type="text" class="textright" placeholder="请输入" v-model="idcard" style="width: 80%;">
				</view>
				<view class="xiahuaxian">
					<view class=" flexbetween margin_top">
						<view class="ershiba nofonweight xiaohei">标签</view>
						<view class="flexright">
							<input class="textright margin_right2" type="text" placeholder="请输入后添加" v-model="bqtext"
								@confirm="addsheshi">
							<u-icon name="plus-square-fill" color="#1BA95B" size="28"
								@click="addsheshi"></u-icon>
						</view>
					</view>
					<view class="flexleft flex_wrap">
						<view class="lvbtn margin_top1 margin_right1 flexleft" v-for="(item,index) in bqarr"
							:key="index">
							<text class="margin_right1">{{item}}</text>
							<u-icon name="close-circle" color="#999" size="16" @click="bqarr.splice(index,1)"></u-icon>
						</view>
					</view>
				</view>
				<view class="ershiba nofonweight xiaohei margin_top">介绍</view>
				<view class="margin_top">
					<u--textarea v-model="des" placeholder="请输入" count></u--textarea>
				</view>
			</view>
		</view>
		<view class="gudingdb ffffff mainpadding">
			<view class="bigbtn" @click="submit">保存</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				show: false,
				logo:"",
				logo_text:"",
				images: [],
				images_text: [],
				des: "",
				mobile: "",
				upvalue: 0,
				bqtext: "",
				bqarr: [],
				name: "",
				gender: "1",
				age: "",
				idcard: "",
				listid: "",
				type:"",//如果为1的话是教练自己编辑自己信息
				user_zbfapply_listid:""
			}
		},
		onLoad(options) {
			this.user_zbfapply_listid=options.user_zbfapply_listid
			this.listid = options.id
			if(options.type){
				this.type = options.type
			}
			this.getDetail()
		},
		methods: {
			addsheshi(){
				if(this.bqtext==""){
					httpRequest.toast("请输入后添加")
					return false
					
				}
				this.bqarr.push(this.bqtext);
				this.bqtext=''
			},
			getDetail() {
				httpRequest.request('/api/user/cgJlDetail', 'GET', {
					jl_user_zbfapply_id: this.listid,
					user_zbfapply_id:this.user_zbfapply_listid
				}).then(res => {
					let data = res.data
					this.logo = data.logo
					this.logo_text = data.logo_text
					this.images = data.images ? data.images.split(",") : []
					this.images_text = data.images_text
					this.mobile = data.mobile
					this.bqarr = data.bq_names_text
					this.des = data.des
					this.name = data.name
					this.age = data.age
					this.gender = data.gender.toString()
					this.idcard = data.idcard
				})
			},
			submit() {
				if (!this.images.length) {
					httpRequest.toast("请上传详情图")
					return false
				}
				if (this.name == "") {
					httpRequest.toast("请输入教练名称")
					return false
				}
				if (this.age == "") {
					httpRequest.toast("请输入教练年龄")
					return false
				}
				if (this.idcard == "") {
					httpRequest.toast("请输入身份证号")
					return false
				}
				if (this.des == "") {
					httpRequest.toast("请输入介绍")
					return false
				}
				uni.showLoading({
					mask:true,
					title:"请稍后"
				})
				let url = "/api/user/editJlInfo"
				let data = {
					images: this.images.join(),
					bq_names: this.bqarr.join(),
					mobile: this.mobile,
					des: this.des,
					idcard: this.idcard,
					name: this.name,
					age: this.age,
					gender: this.gender,
					logo:this.logo,
					id: this.listid,
					user_zbfapply_id:this.user_zbfapply_listid
				}
				if(this.type==1){
					url = "/api/user/editJlbInfo"
				}
				httpRequest.request(url, 'POST', data).then(res => {
					uni.hideLoading()
					httpRequest.toast(res.msg)
					if (res.code == 1) {
						setTimeout(() => {
							uni.navigateBack(1)
						}, 1000)
					}
				})
			},

			bindPickerChange(val) {
				let area = val.detail.value
				let area_text = [area[0].text, area[1].text, area[2].text];
				this.city_text = area_text.join("/")
				this.province_id = area[0].value;
				this.city_id = area[1].value;
				this.area_id = area[2].value;
			},

			uploadImg(value, upImgs, upImgs_text) { //上传图片
				let _this = this;
				this.upvalue = value
				let num = 0
				if (value == 5) {
					num = Number(value) - upImgs.length;
					if (num <= 0) {
						return false;
					}
				} else {
					num = 1
				}
				uni.showActionSheet({
					itemList: ['相机', '相册'],
					success: function(res) {
						// 选择相机走0
						if (res.tapIndex == 0) {
							httpRequest.chooseImage(num, ['camera']).then(res => {
								for (var i = 0; i < res.length; i++) {
									_this.uploadImageService(res[i], upImgs, upImgs_text)
								}
							}).catch(err => {});
						}
						// 选择相册走1
						if (res.tapIndex == 1) {
							httpRequest.chooseImage(num, ['album']).then(res => {
								for (var i = 0; i < res.length; i++) {
									_this.uploadImageService(res[i], upImgs, upImgs_text)
								}
							}).catch(err => {});
						}
					},
					fail: function(res) {}
				});
			},
			delindex(index, upImg, upImgs_text) {
				upImg.splice(index, 1)
				upImgs_text.splice(index, 1)
			},
			uploadImageService(url, upImg, upImgs_text) {
				let _this = this;
				httpRequest.uploadFile('/api/common/upload', url).then(res => {
					let image_item = res.fullurl;
					if (this.upvalue == 1) {
						this.logo = res.url
						this.logo_text = image_item
						return false
					}
					upImg.push(res.url)
					upImgs_text.push(image_item);
				}).catch(err => {});
			},
			upvideo() { //上传视频
				let uploadFile = ''
				let _this = this;
				// 1.选择要上传的视频
				uni.chooseVideo({
					maxDuration: 60, // 拍摄视频最长拍摄时间，单位秒。最长支持 60 秒。
					sourceType: ['album', 'camera'], // album 从相册选视频，camera 使用相机拍摄，默认为：['album', 'camera']
					success: function(res) {
						_this.uploadImageServicet(res.tempFilePath)
					}
				});
			},
			uploadImageServicet(url, upImg, upImgs_text) {
				let _this = this;
				httpRequest.uploadFile('/api/common/upload', url).then(res => {
					let image_item = res.fullurl;
					this.video = res.url
					this.video_text = image_item
				}).catch(err => {});
			},
			delvideo() {
				this.video = ""
				this.video_text = ""
			}
		}
	}
</script>

<style lang="scss" scoped>
	.huibtn {
		background: #F9F9F9;
		border-radius: 8rpx 8rpx 8rpx 8rpx;
		padding: 15rpx 30rpx;
		font-size: 28rpx;
		font-family: PingFang SC-Regular, PingFang SC;
		font-weight: 400;
		color: #777777;
	}

	.lvbtn {
		background: #DFFFED;
		border-radius: 8rpx 8rpx 8rpx 8rpx;
		padding: 15rpx 30rpx;
		font-size: 28rpx;
		font-family: PingFang SC-Regular, PingFang SC;
		font-weight: 400;
		color: #1BA95B;
	}

	.touxiang {
		width: 60rpx;
		height: 60rpx;
		border-radius: 50%;

		image {
			border-radius: 50%;
			width: 100%;
			height: 100%;
		}
	}

	.dizneo {
		height: 500rpx;
		overflow: auto;
	}

	.xiaolbtn {
		width: 112rpx;
		height: 48rpx;
		background: rgba(27, 169, 91, 0.1);
		border-radius: 24rpx 24rpx 24rpx 24rpx;
		font-size: 24rpx;
		font-family: PingFang SC-Regular, PingFang SC;
		font-weight: 400;
		color: #1BA95B;
		border: 2rpx solid #1BA95B;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	page {

		background: #F9F9F9;
	}

	.shanchu {
		position: absolute;
		top: -10rpx;
		right: -10rpx;
	}

	.shanchu2 {
		position: absolute;
		bottom: -10rpx;
		right: -50%;
		transform: translate(0, -50%);
	}

	.shilitu {
		width: 160rpx;
		height: 160rpx;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.shangc {
		width: 160rpx;
		height: 160rpx;

		image {
			width: 100%;
			height: 100%;
		}
	}
</style>